<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加菜单</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>

<form class="layui-form" style="width: 80%;" id="menuF">

    <input type="hidden" name="parentId" th:value="${menu.parentId}"/>
    <input type="hidden" name="id" th:value="${menu.id}"/>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名</label>
        <div class="layui-input-block">
            <input type="text" id="title" class="layui-input"
                   lay-verify="required" placeholder="请输入菜单名" name="title" th:value="${menu.title}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标</label>
        <div class="layui-input-block">
            <input type="text" id="iconPicker" lay-filter="iconPicker" class="layui-input"
                   placeholder="请填写图标代码" name="icon" th:value="${menu.icon}">
            <label></label>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源路径</label>
        <div class="layui-input-block">
            <input type="text" name="href" class="layui-input"
                   placeholder="请输入资源路径" th:value="${menu.href}">
            <label>（<span style="color: red">*</span>例：log/logList）</label>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限标识</label>
        <div class="layui-input-block">
            <select name="permissionId" lay-verify="" style="width: 200px">
                <option value="">-请选择权限-</option>
                <option th:each="p:${perms}" th:value="${p.id}" th:selected="${p.id == menu.permissionId}">[[${p.title}]]</option>
            </select>
        </div>

    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="menuForm">立即提交</button>
        </div>
    </div>
</form>
<script th:src="@{/src/layui.js}"></script>
<script>
    layui.config({
        base:'/src/app/'
    }).use(['iconPicker','form','layer','jquery'],function () {
        var iconPicker = layui.iconPicker,
            form = layui.form,
            $ = layui.jquery,
            layer = layui.layer;


        iconPicker.render({
            elem:'#iconPicker',
            type:"unicode",
            search: true,
            page:true,
            limit:12
        })


        form.on('submit(menuForm)',function (data) {
            $.ajax({
                url:'/menus/update',
                type:'put',
                dataType:'json',
                data:data.field,
                success:function (result) {
                    if(result.code == 200){
                        layer.msg('更新成功',{icon:1,time:1000},function () {
                            parent.layer.closeAll("iframe");
                            parent.location.reload();
                        })
                    }else{
                        layer.msg(result.message,{icon:5});
                    }
                }
            })

            return false;
        })




    })
</script>
</body>
</html>